<template>
	<z-paging ref="paging" bgColor="transparent" class="content" :loading-more-enabled="false" hide-empty-view v-model="data" @query="queryList">
		<template #top>
			<my-navbar
				:bgUrl="`${$imgurl}/static/mj-bg.png`"
				title="规则玩法说明"
				title-color="#fff"
				leftIconColor="#fff"
				:scrollTop="scrollTop"
				:autoBack="true"
			/>
			<view class="box tab-box">
				<view class="item" @click="onTab(index)" :class="{on:tab_i==index}" :style="tab_i==index?`background: url(/static/tab-bg.png) no-repeat; background-size: 100% 100%;padding-bottom:12rpx`:''" v-for="(item,index) in tab">
					<view class="bg" >{{item.name}}</view> 
				</view>
			</view>
		</template>
		
		
		<view class="box goods-box" v-if="data!=''">
			<view class="img">
				<image :src="data.gift_rules_image" v-if="tab_i==0" mode="widthFix"></image>
				<image :src="data.lottery_rules_image" v-else-if="tab_i==1" mode="widthFix"></image>
				<image :src="data.gold_coin_rules_image" v-else-if="tab_i==2" mode="widthFix"></image>
				<image :src="data.activity_rules_image" v-else mode="widthFix"></image>
			</view>
	
		</view>

		<view class="box goods-box" v-if="data!=''">
			<view class="title">
				特殊说明
			</view>
			<view class="tip-box">
				<view v-if="tab_i==0">
					{{data.gift_rules}}
				</view>
				<view v-else-if="tab_i==1">
					{{data.lottery_rules}}
				</view>
				<view v-else-if="tab_i==1">
					{{data.gold_coin_rules}}
				</view>
				<view v-else>
					{{data.activity_rules}}
				</view>
			</view>
		</view>
		
		<template #bottom>
			<view class="btn-box">
				<view class="it" @click="onAnswer()">
					去下单，开启谜货
				</view>
			</view>
		</template>
	</z-paging>
</template>

<script setup>
	import {ref} from "vue"
	import {onLoad} from "@dcloudio/uni-app"
	import {getRulesInfoApi} from "@/api/public.js"
	const tab_i=ref(0)
	const tab=ref([
		{
			name:'谜礼'
		},
		{
			name:'谜奖'
		},
		{
			name:'谜金'
		},
		{
			name:'活动介绍'
		}
	])
	
	// 使用 reactive 创建响应式对象  
	const paging=ref(null)
	const data=ref('')
	const onTab=(e)=>{
		tab_i.value=e
	}
	onLoad(async (obj)=>{
		if(obj.type){
			tab_i.value=obj.type
		}
	})
	const queryList=async (pageNo, pageSize)=>{
		//请求接口数据
		const res=await getRulesInfoApi()
		data.value=res.data
		paging.value.complete([]);
	}
	const onAnswer = async ()=>{
		uni.redirectTo({
			url:'/pages/goods/category'
		})
	}

</script>

<style lang="scss">
	page{
		background-color: #F5F6FA;
		position: relative;
		
	}
	.content{
		::v-deep{
			// .zp-view-super{
			// 	background-color: #F5F6FA;
			// }
		}
	}
	.tab-box{
		display: flex;
		gap: 26rpx;
		padding-top:20rpx;
		align-items: flex-start;
		.item{
			flex:1;
			text-align: center;
			background:#FFFED9;
			line-height: 72rpx;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			color:#E02500;
			font-weight: bold;font-size: 32rpx;
			position: relative;
			
			&.on{
				background: linear-gradient( 138deg, #FFA640 0%, #FF401A 100%);
				.bg{
					 background: -webkit-linear-gradient(#FFFFFF, #FFF3E0);
					    -webkit-background-clip: text;
					    -webkit-text-fill-color: transparent;
					    /* 为了更好的兼容性，可以添加下面的属性 */
					    background-clip: text;
					    color: transparent; /* 确保文本颜色透明 */
				}
			}
		}
	}
	
	.goods-box{
		padding:28rpx;
		background-color: #fff;
		margin-top:20rpx;
		border-radius: 20rpx;
		padding-bottom: 0;
		.title{
			display: flex;
			font-size: 32rpx;
			font-weight: bold;
			justify-content: space-between;
			.a{
				display: flex;align-items: center;font-size: 24rpx;
				color:#9BA2AB;
				font-weight: initial;
			}
		}
		.tip-box{
			font-size: 28rpx;
			color:#141311;
			line-height: 48rpx;
			margin-top:28rpx;
			padding-bottom: 24rpx;
		}
		.img{
			padding-bottom: 28rpx;
			image{
				width:100%;display: block;
			}
		}
		
	}
	
	
	.btn-box{
		background-color: #fff;

		padding:16rpx 32rpx;
		padding-bottom: calc(16rpx + env(safe-area-inset-bottom) );
		.it{
			font-size: 32rpx;
			font-weight: bold;
			color:#fff;
			text-align:center;
			line-height: 92rpx;
			background: linear-gradient(to right,#FF9940,#FD2A00);
			border-radius: 80rpx;
		}
	}
</style>
